<?php

class tuanqi {
	
	private $daystr;	//日期字符串
	private $fatuanday;		//处理过的日期
	private $price;		//价格
	private $yuwei;		//余位
	
	public function makeriqi($mstr) {
	$quriqi = explode ( '至', $mstr );
	$startriqi = $quriqi [0];
	$finalriqi = $quriqi [1];
	$fatuan = array ();
	$fatuan ['0'] = $startriqi;
	$ff = strtotime ( $finalriqi );
	
	$ss = strtotime ( $startriqi );
	$si = 1;
	while ( $ss < $ff ) {
		$ss = strtotime ( $startriqi ) + 24 * 60 * 60 * $si;
		$fatuan [$si] = date ( 'Y-m-d', $ss );
		$si ++;
		}
	//echo $this->fatuanday;
	return $this->faday = implode ( '、', $fatuan );
	}
	
	//处理包含‘至’
	public function zhiday($zstr){
		$faa = array();		
		$faa = explode ( '、', $zstr );
		//print_r($faa);
		$irq = count ( $faa );
		
		for($ir = 0; $ir < $irq; $ir ++) {
			$this->fatuanday .= $this->makeriqi ( $faa[$ir]  );
			if(($ir+1) !== $irq){
			$this->fatuanday .= '、';
				}
			}
		//echo $this->fatuanday;
		return $this->fatuanday;
	}
	
	//处理‘天天发团’
	public function dayday(){
	$this->fatuanday = date ( 'Y-m-d', strtotime ( '1 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '2 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '3 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '4 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '5 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '6 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '7 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '8 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '9 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '10 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '11 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '12 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '13 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '14 day' ) ) . "、" . date ( 'Y-m-d', strtotime ( '15 day' ) ). "、" . date ( 'Y-m-d', strtotime ( '16 day' )). "、" . date ( 'Y-m-d', strtotime ( '17 day' )). "、" . date ( 'Y-m-d', strtotime ( '18 day' )). "、" . date ( 'Y-m-d', strtotime ( '19 day' )). "、" . date ( 'Y-m-d', strtotime ( '20 day' ));
	
	return $this->fatuanday;
	}
	//处理‘每周’
	public function meiday($zstr){
	$arr6 = array();
//preg_match('/[一二三四五六日]/',$fatuanday,$arr6);
//echo $arr6[1];
	if(strstr($zstr,'一')) $arr6[] = 1;
	if(strstr($zstr,'二')) $arr6[] = 2;
	if(strstr($zstr,'三')) $arr6[] = 3;
	if(strstr($zstr,'四')) $arr6[] = 4;
	if(strstr($zstr,'五')) $arr6[] = 5;
	if(strstr($zstr,'六')) $arr6[] = 6;
	if(strstr($zstr,'日')) $arr6[] = 7;
	
	//一二三四五六日
//	print_r($arr6);
	$fatuanzhou = array();
	$ix=1;
	//$timem = mktime ( 1, 1, 1, $month, 1, $year );
	foreach($arr6 as $zhouji)
	{
		$long = count($arr6);
		 $jint = date ( "N", time());
		 $cha = $jint - $zhouji;	
		$fatuanzhou[$ix] = date("Y-m-d",strtotime( "-$cha day"));
		$cha = -$cha+7;
		$fatuanzhou[$ix+$long] = date("Y-m-d",strtotime( "$cha day"));
		$cha = $cha+7;
		$fatuanzhou[$ix+$long*2] = date("Y-m-d",strtotime( "$cha day"));
		$cha = $cha+7;
		$fatuanzhou[$ix+$long*3] = date("Y-m-d",strtotime( "$cha day"));
		$cha = $cha+7;
		$fatuanzhou[$ix+$long*4] = date("Y-m-d",strtotime( "$cha day"));
		$cha = $cha+7;
		$fatuanzhou[$ix+$long*5] = date("Y-m-d",strtotime( "$cha day"));
		
		$ix++;
	}
	//排序
	ksort($fatuanzhou);
	$fatuanday = implode('、',$fatuanzhou);
	return $fatuanday;
	}

	
}

	//$lday = new tuanqi();
	//echo $lday->dayday("天天发团");
	//echo $lday->zhiday("2011-06-03至2011-06-06、2011-06-13至2011-06-16");
	//echo $lday->zhiday("2011-06-03至2011-06-05");
	//echo $lday->makeriqi("2011-06-07至2011-06-09");
	//echo $lday->meiday("每周五六");
	
?>